﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;
using MarginTrading.Services;
using MarginTrading.Common;
using MarginTrading.Entity;

namespace MarginTrading.Forms
{
    public partial class PortfolioValuation1 : Form
    {
        public PortfolioValuation1()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            LoadReport(txtClientID.Text);
        }

        private void txtClientID_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 13)
            {
                LoadReport(txtClientID.Text);
            }
        }

        private void LoadReport(string clientId)
        {
            Client client = ClientService.GetClientByCode(clientId);

            if (client == null)
            {
                client = new Client();
            }
            ReportDataSource ds = new ReportDataSource();
            ds.Name = "master";
            ds.Value = ReportServices.GetPortfolioValuation1(clientId);
            

            this.reportViewer1.LocalReport.ReportPath = "PortfolioValuation1.rdlc";
            this.reportViewer1.LocalReport.DataSources.Clear();
            this.reportViewer1.LocalReport.DataSources.Add(ds);

            this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] {
                        new ReportParameter("CompanyName",Reports.COMPANY_NAME),
                        new ReportParameter("ClientID",client.Code),
                        new ReportParameter("Name",string.Concat(client.Initials, " ",client.OtherNames, " ", client.Surname) ),
                        new ReportParameter("Address",client.Address_1),
                        new ReportParameter("AdvisorID",client.Advisor)});
            this.reportViewer1.RefreshReport();

        }
    }
}
